package com.zxw.flow.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zxw.common.web.util.JwtUtils;
import com.zxw.flow.domain.entity.FlowBasicInfo;
import com.zxw.flow.domain.entity.FlowBasicInfo;
import com.zxw.flow.domain.vo.FlowBasicInfoPageVO;
import com.zxw.flow.domain.vo.FlowBasicInfoVO;
import com.zxw.flow.mapper.FlowBasicInfoMapper;
import com.zxw.flow.service.FlowBasicInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Xuewei.Zhang
 * @since 2022-07-04
 */
@Service
@RequiredArgsConstructor
public class FlowBasicInfoServiceImpl extends ServiceImpl<FlowBasicInfoMapper, FlowBasicInfo> implements FlowBasicInfoService {

    private final FlowBasicInfoMapper flowBasicInfoMapper;

    @Override
    public IPage<FlowBasicInfo> getPage(FlowBasicInfoPageVO pageVO) {
        Page<FlowBasicInfo> flowTypeDTOPage = new Page<>(pageVO.getPageNum(), pageVO.getPageSize());
        LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper<FlowBasicInfo>()
                .eq(FlowBasicInfo::getCompanyId, pageVO.getCompanyId())
                .eq(null != pageVO.getTitle(), FlowBasicInfo::getTitle, pageVO.getTitle())
                .eq(null != pageVO.getServiceType(), FlowBasicInfo::getServiceType, pageVO.getServiceType());
        Page<FlowBasicInfo> pageData = flowBasicInfoMapper.selectPage(flowTypeDTOPage, wrapper);
        return pageData;
    }

    @Override
    public FlowBasicInfoVO add(FlowBasicInfoVO flowBasicInfoVO) {
        flowBasicInfoMapper.insert(flowBasicInfoVO);
        return flowBasicInfoVO;
    }

    @Override
    public FlowBasicInfo getFlowBasicInfoById(Long id) {
        Long companyId = JwtUtils.getCompanyId();
        return flowBasicInfoMapper.selectOne(new LambdaQueryWrapper<FlowBasicInfo>()
                .eq(FlowBasicInfo::getCompanyId, companyId)
                .eq(FlowBasicInfo::getId, id)
        );
    }

    @Override
    public void updateBase(FlowBasicInfoVO flowBasicInfoVO) {
        flowBasicInfoMapper.update(flowBasicInfoVO, new LambdaUpdateWrapper<FlowBasicInfo>()
                .eq(FlowBasicInfo::getId, flowBasicInfoVO.getId())
                .eq(FlowBasicInfo::getCompanyId, flowBasicInfoVO.getCompanyId())
        );
    }

    @Override
    public void delete(String flowBasicInfoIds) {
        Long companyId = JwtUtils.getCompanyId();
        flowBasicInfoMapper.delete(new LambdaQueryWrapper<FlowBasicInfo>()
                .eq(FlowBasicInfo::getCompanyId,companyId)
                .in(FlowBasicInfo::getId, flowBasicInfoIds)
        );
    }
}
